type FnAbort<F extends (...args: any[]) => unknown> = (
  ...params: [...Parameters<F>, (abort: () => void) => void]
) => ReturnType<F>;

const latest_strict = <T extends (...args: any[]) => unknown>(fn: FnAbort<T>): T => {
  let lastAbort = () => {
    0;
  };

  return ((...params: Parameters<T>) => {
    lastAbort();

    return fn(...params, (abort: () => void) => {
      lastAbort = abort;
    });
  }) as unknown as T;
};

function latest(fn, abortReason) {
  let latestKey;
  return async (...params) => {
    const thisKey = Symbol('kkk');
    latestKey = thisKey;
    const res = await fn(...params);
    if (latestKey !== thisKey) {
      throw new Error('cancel because expired');
    }
    return res;
  };
}
// const onSearch = latest(getList)
/**
 * 考虑unify，实现专门的 unifyAxios、具有unify的功能，但所有调用同时cancel 才能触发cancel
 */
